package com.rao.travel.controller;

import com.rao.travel.pojo.Permission;
import com.rao.travel.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author Srao
 * @version 1.0
 * @className PermissionController
 * @date 2019/11/5 10:24
 * @package com.rao.travel.controller
 * @description 资源权限管理
 */
@RequestMapping("permission")
@Controller
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /*查询所有权限*/
    @RequestMapping("findAll.do")
    public ModelAndView findAll(){
        ModelAndView modelAndView = new ModelAndView();
        List<Permission> permissionList = permissionService.findAll();
        modelAndView.addObject("permissionList", permissionList);
        modelAndView.setViewName("permission-list");
        return modelAndView;
    }

    /*保存权限*/
    @RequestMapping("save.do")
    public String save(Permission permission){
        permissionService.save(permission);
        return "redirect:findAll.do";
    }

    /*查看权限详情*/
    @RequestMapping("findById.do")
    public ModelAndView findById(@RequestParam(name = "id")String id){
        ModelAndView modelAndView = new ModelAndView();
        Permission permission = permissionService.findById(id);
        modelAndView.addObject("permission", permission);
        modelAndView.setViewName("permission-show");
        return modelAndView;
    }

    /*删除权限*/
    @RequestMapping("deleteById.do")
    public String deleteById(@RequestParam(name = "id")String id){
        permissionService.deleteById(id);
        return "redirect:findAll.do";
    }
}
